package spitter.web;

import org.springframework.stereotype.Repository;
import spittr.Spitter;
import spittr.Spittle;
import spittr.data.SpittleRepository;

import java.util.*;

/**
 * Created by gongyan on 17/4/5.
 */
@Repository
public class SpittleRepositoryImpl implements SpittleRepository {

    private final static Map<String,Spitter> VIR_DB = new HashMap<String,Spitter>(10);

    @Override
    public List<Spittle> findSpittles(long max, int count) {
        List<Spittle> spittles = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            spittles.add(new Spittle("Spittle" + i, new Date()));
        }
        return spittles;
    }

    @Override
    public void save(Spitter spitter) {
        VIR_DB.put(spitter.getUserName(),spitter);
    }

    @Override
    public Spitter findByUserName(String userName) {
        return VIR_DB.get(userName);
    }
}
